import fetcher from "../apis/Fetcher";
import {Page, Pageable} from "../utils/Page";
import {NumberIdAndName} from "../types/BasicModels";

export interface QueryGoodsCategoriesRequest {
    name?: string
}

export function queryGoodsCategories(queryGoodsCategoriesRequest: QueryGoodsCategoriesRequest, pageable: Pageable) {
    return fetcher.get<Page<QueryGoodsCategoriesResponse>>("/goodsCategories", {...queryGoodsCategoriesRequest, ...pageable.toRequestParams()})
}

export interface QueryGoodsCategoriesResponse{
    id:number
    name:string
    goodsAmount:number
}

export interface CreateGoodsCategoryRequest{
    name:string
}

export function createGoodsCategory(createGoodsCategoryRequest:CreateGoodsCategoryRequest){
    return fetcher.post("goodsCategories",{},createGoodsCategoryRequest)
}

export function updateGoodsCategory(id:number,createGoodsCategoryRequest:CreateGoodsCategoryRequest){
    return fetcher.put(`goodsCategories/${id}`,{},createGoodsCategoryRequest)
}

export function getAllGoodsCategories(){
    return fetcher.get<Array<NumberIdAndName>>("goodsCategories")
}



export function deleteGoodsCategory(id:number){
    return fetcher.delete(`goodsCategories/${id}`)
}